package com.hdaccp.beike
import org.apache.spark.sql.SparkSession
/**
  * DataFrame - sql
  */
object Demo2 {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder()
      .master("local[2]")
      .appName("beikeDemo2App")
      .getOrCreate()

    //引入隐式转换
    import spark.implicits._

    //读取一个json文件
    val dataFrame = spark.read.json("F:/resources/people.json")

    //将DataFrame注册为SQL临时视图
    dataFrame.createOrReplaceTempView("people")

    dataFrame.sqlContext.sql("select * from people").show()
    println("------------------------------") ;
    dataFrame.sqlContext.sql("select * from people where age >21").show()
    println("-------------------------------");
    dataFrame.sqlContext.sql("select count(age),name from people group by name").show()

    spark.stop()
  }
}
